<?php

    class AdminLoginForm extends Form
    {
        const FIELD_USERNAME        = 'username';
        const FIELD_PASSWORD        = 'password';

        protected static $errorMap = array(
            'username_required'       => array('message' => 'Please enter a valid Username and Password.', 'level' => self::ERROR_LEVEL_ERROR, 'field_name' => 'Username'),
            'password_required'    => array('message' => 'Please enter a valid Username and Password.', 'level' => self::ERROR_LEVEL_ERROR, 'field_name' => 'Password')
        );

        protected function GetTemplatePath()
        {
            return 'include/admin/login_form.tpl';
        }

        public function Setup()
        {
            $this->SetFields( array(
                self::FIELD_USERNAME, self::FIELD_PASSWORD
            ));
        }

        protected function Validate()
        {
            parent::Validate();
            
            $username = trim($this->GetParamValue(self::FIELD_USERNAME));
            if (!empty($username))
            {
                $this->SetValue(self::FIELD_USERNAME, $username);
            }
            else
            {
                $this->SetError(self::FIELD_USERNAME, self::$errorMap['username_required']);
            }

            $password = trim($this->GetParamValue(self::FIELD_PASSWORD));
            if (!empty($password))
            {
                $this->SetValue(self::FIELD_PASSWORD, $password);
            }
            else
            {
                $this->SetError(self::FIELD_PASSWORD, self::$errorMap['password_required']);
            }          
        }
    }

?>